package unilearn.facade;

import java.sql.Date;
import java.sql.SQLException;
import java.util.Vector;

import unilearn.da.DAAssignment;
import unilearn.domain.Assignment;
import unilearn.domain.Submission;

/**
 * @author David Oliver, 4084551
 * @version 0.1 Apr 30, 2008, initial creation, dro
 * @version 0.2 Apr 30, 2008, added basic insert/update/delete methods, dro
 */
public class AssignmentFacade
{
	public static long insertAssignment(Assignment assign) throws SQLException
	{
		return DAAssignment.insertAssignment(assign);
	}

	public static Assignment getAssignmentByID(long assignmentID) throws SQLException
	{
		return DAAssignment.getAssignmentByID(assignmentID);
	}

	public static Vector<Assignment> getAssignmentBySubject(long subjectID)
		throws SQLException
	{
		// TODO Fix DAAssignment
		return DAAssignment.getAssignmentBySubject(subjectID);
	}

	public static Assignment getAssignmentBySubmission(Submission sub) throws SQLException
	{
		long assignmentID = sub.getAssignmentID();
		return getAssignmentByID(assignmentID);
	}

	public static Assignment createAssignment(String name, String description, Date dueDate,
			boolean acceptSubmissions, Date releaseDate, long subjectID, long fileID)
		throws SQLException
	{
		Assignment assign = new Assignment();
		assign.setAssignmentName(name);
		assign.setAssignmentDescription(description);
		assign.setAssignmentDueDate(dueDate);
		assign.setAssignmentAcceptingSubmissions(acceptSubmissions);
		assign.setAssignmentReleaseDate(releaseDate);
		assign.setAssignmentSubjectID(subjectID);
		assign.setAssignmentFileID(fileID);

		return assign;
	}

	public static void updateAssignment(long assignmentID, Assignment assign)
		throws SQLException
	{
		DAAssignment.updateAssignment(assignmentID, assign);
	}

	public static void deleteAssignment(long assignmentID) throws SQLException
	{
		DAAssignment.deleteAssignment(assignmentID);
	}
}
